﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<meta name="author" content="featon inc.">
	<link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap-theme.min.css">
	<link rel="stylesheet" href="/static/vendor/font-awesome/css/font-awesome.min.css">
	<link rel="stylesheet" href="/static/vendor/skin/ftskin.css">
	<title></title>
</head>

<body style="margin-bottom: 60px;">

<div class="ft-subpage-wrapper container-fluid"> 
<form id="form1" name="form1" action="#" method="post">
  <div class="row">
    <div class="col-lg-12" id="form_table">                	
			<table id="" class="form-table-border" cellpadding="0" cellspacing="0" style="width:100%">
				<tr>
					<th><span class="f_red">*</span>权限名称</th>
					<td>						
						<input id="opt_name" name="opt_name" type="text" class="form-control" value="" placeholder="">
						<span class="cError"></span>
					</td>
				</tr>	
				<tr>
					<th><span class="f_red">*</span>权限编码</th>
					<td>					
						<input id="opt_code" name="opt_code" type="text" class="form-control" value="" placeholder="">
						<span class="cError"></span>
						
					</td>
				</tr>
				<tr>
					<th>权限说明</th>
					<td>
						<textarea id="opt_memo" name="opt_memo" class="form-control" rows="3" ></textarea>
					</td>
				</tr>				
			</table>

			
		</div>
	</div> 
</form>
</div>
<div class="iframe-bottom-tools-box nav navbar-fixed-bottom">
	<button type="button" class="btn btn-info"  id="save_but"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span> 保存</button>
	<button type="button" class="btn btn-warning" onclick="modelWindow.closeFrameWindow();"><span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span> 取消</button>
</div>
<script src="/static/vendor/jquery/jquery-3.3.1.min.js"></script>
<script src="/static/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/vendor/validate/jquery.validate.min.js" type="text/javascript"></script>
<script src="/static/vendor/skin/js/ft-ui.js"></script>
<script src="/static/vendor/skin/js/jquery.c.js"></script>
<script src="/static/vendor/skin/js/java.js"></script>

<script>
var parentID  = [[${parentID}]];
var opt_id = [[${opt_id}]];
jQuery(function($) {
 	iniInfoForm();
	if(opt_id != "" && opt_id != null)
	{		
		defaultBean = top.ajax.syncl("/operate/getOperateBean/"+opt_id,"");
		if(defaultBean)
		{
			$("#form_table").autoFill(defaultBean);	
			$('#save_but').click(UpdateObject)
		}

	}else {
		$('#save_but').click(addObject)
	}
});

$(document).ready(function(){
		
});

function iniInfoForm()
{
	var validator = $("#form1").validate({
    debug:true,
    rules: {
	  opt_name: {
        required: true
      },
	  opt_code: {
        required: true
      }
    },
    messages: {
      opt_name: {
        required: "权限名称不能为空！"
      },
	  opt_code: {
        required: "权限编码不能为空！"
      }
    },    
    errorPlacement: function(error, element) {
      error.appendTo( element.parents('td').find(".cError") );
     // error.appendTo(element.parent());
    },
    submitHandler: function(form) {
      
    }
  });
}

var is_submit = false;
function addObject()
{	
	if($("#form1").valid())
	{
		if(is_submit == false)
		{
			is_submit = true;
			var bean = top.ajax.getBean("com.yixun.entity.YxOperate");//获取空的bean对象,再使用autoBind将form里的input值写到对象中
			$("#form_table").autoBind(bean);
			bean.parent_id = parentID;

			if(top.ajax.synclBody("/operate/add",bean))
			{
				modelWindow.alert(top.CMSLang.Add_success);
				top.getCurrentFrameObj().insertTreeNode(bean.opt_id,bean.opt_name);
				top.getCurrentFrameObj().loadListble();
				modelWindow.closeFrameWindow();
			}else
			{
				modelWindow.error(top.CMSLang.Add_fail);
				is_submit = false;
			}
		}
	}
}

function UpdateObject()
{
	if($("#form1").valid())
	{
		if(is_submit == false)
		{
			is_submit = true;
			var bean = top.ajax.getBean("com.yixun.entity.YxOperate");//获取空的bean对象,再使用autoBind将form里的input值写到对象中
			$("#form_table").autoBind(bean);
			bean.opt_id = opt_id;
			if(top.ajax.synclBody("/operate/edit",bean))
			{
				modelWindow.alert(top.CMSLang.Add_success);
				top.getCurrentFrameObj().updateTreeNode(bean.opt_id,bean.opt_name);
				top.getCurrentFrameObj().loadListble();
				modelWindow.closeFrameWindow();
			}else
			{
				modelWindow.error(top.CMSLang.Add_fail);
				is_submit = false;
			}
		}
	}
}
</script>
</body>

</html>
